//
// Created by 11510 on 2024/6/17.
//
#include <iostream>
using namespace std;

class Base{
public:
    Base(long base = -1):_base(base){

    }
    Base(const Base& rhs):_base(rhs._base){}

    void print(){
        printf("base = %ld\n", _base);
    }

    Base& operator=(const Base& rhs){
        _base = rhs._base;
        return *this;
    }

    long _base = 10;
};

class Derived:public Base{
public:
    Derived( long base, long derived):
    Base(base),_derived(derived){
    }

    Derived(const Derived& rhs):Base(rhs), _derived(rhs._derived){

    }

    /* 自复制只在有指针指向堆内存时用 */
    Derived& operator=(const Derived& rhs){
//        Base::operator=(rhs);
        _derived = rhs._derived;
        return *this;
    }


    void display(){
        printf("display %ld\n", _derived);
    }
private:
    long _derived = 12;
};


void test0(){
    Base base;
    Derived derived(1, 3);

    base = derived;
    base.print();
}


int main() {
    test0();
    return 0;
}
